package com.example.basic.web.controller.roleVsMenu;


import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.exception.ServiceException;
import com.example.basic.web.model.roleVsMenu.RoleVsMenu;
import com.example.basic.web.service.roleVsMenu.RoleVsMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Api(value = "角色对应菜单相关操作", tags = {"角色对应菜单"})
@RestController
@RequestMapping("/api/v1/byg/roleVsMenu")
public class RoleVsMenuController {
    @Resource
    private RoleVsMenuService roleVsMenuService;

    /**
     * @create 系统用户组和功能批量修改功能
     * @param roleVsMenuList 系统用户组和功能对应关系列表
     * @return
     */
    @Log(title = "角色对应菜单", description = "批量修改角色对应菜单对应关系")
    @ApiOperation("批量修改角色对应菜单对应关系")
    @PostMapping("/batchModify")
    public Result batchModify(
            @ApiParam(name = "roleCode", value = "角色编码") @RequestParam String roleCode,
            @ApiParam(name = "sysType", value = "系统类型") @RequestParam String sysType,
            @ApiParam(name = "roleVsMenuList", value = "角色对应菜单对应关系模型列表")@RequestBody List<RoleVsMenu> roleVsMenuList){
        boolean result = roleVsMenuService.batchModify(roleCode,sysType,roleVsMenuList);
        if (result){
            return ResultGenerator.genSuccessResult("修改成功！");
        }else{
            throw new ServiceException("修改失败");
        }
    }

    /**
     * @create 查询角色对应菜单对应关系列表
     * @param roleCode 角色代码
     * @return
     */
    @Log(title = "角色对应菜单", description = "查询角色对应菜单对应关系列表")
    @ApiOperation(value="查询角色对应菜单对应关系列表",notes = "查询角色对应菜单对应关系列表")
    @PostMapping("/queryList")
    public Result queryList(
            @ApiParam(name = "roleCode", value = "角色编码") @RequestParam String roleCode,
            @ApiParam(name = "sysType", value = "系统类型") @RequestParam String sysType) {

        return ResultGenerator.genSuccessResult(roleVsMenuService.queryList(roleCode,sysType));
    }
}